<template>
  <div class="taskOverview">
    <div class="mains_contain">
      <div class="back" @click="$router.go(-1)">
        <i class="el-icon-back"></i>
        <span>返回</span>
      </div>
      <el-divider content-position="left">
        <div class="hTitle">任务概况</div>
      </el-divider>
      <el-card class="box-card">
        <table class="curTable">
          <tr>
            <td width="200">
              <span class="comSpan">任务名称：</span>{{ row.taskName }}
            </td>
            <td width="200">
              <span class="comSpan">任务类型：</span>
              <!-- <el-tag type="success" effect="dark">{{
                row.taskType | getTypeName(typeList)
              }}</el-tag> -->
              <span style="color:#67C23A">{{
                row.taskType | getTypeName(typeList)
              }}</span>
            </td>
            <td width="200">
              <span class="comSpan">任务状态：</span>
              <!-- <el-tag
                type="success"
                effect="dark"
                v-if="row.taskStatus == 'created'"
                >未执行</el-tag
              >
              <el-tag
                type="success"
                effect="dark"
                v-if="row.taskStatus == 'issued'"
                >已执行</el-tag
              >
              <el-tag
                type="success"
                effect="dark"
                v-if="row.taskStatus == 'executing'"
                >执行中</el-tag
              >
              <el-tag
                type="success"
                effect="dark"
                v-if="row.taskStatus == 'finished'"
                >已完成</el-tag
              >
              <el-tag
                type="danger"
                effect="dark"
                v-if="row.taskStatus == 'failed'"
                >失败</el-tag
              > -->
              <span style="color:#67C23A" v-if="row.taskStatus == 'created'">未执行</span>
              <span style="color:#67C23A" v-if="row.taskStatus == 'issued'">已执行</span>
              <span style="color:#67C23A" v-if="row.taskStatus == 'executing'">执行中</span>
              <span style="color:#67C23A" v-if="row.taskStatus == 'finished'">已完成</span>
              <span style="color:#F56C6C" v-if="row.taskStatus == 'failed'">失败</span>

            </td>
          </tr>
          <tr>
            <td width="200"><span class="comSpan">创建人：</span> admin</td>
            <td width="200">
              <span class="comSpan">创建时间：</span>
              {{ row.createTime | formatTime }}
            </td>
            <td width="200">
              <span class="comSpan">优先级：</span>
              <!-- <el-tag type="danger" effect="dark">{{
                row.taskPriority
              }}</el-tag> -->
              <span style="color:#F56C6C">{{  row.taskPriority }}</span>
            </td>
          </tr>
        </table>
      </el-card>
      <el-divider content-position="left">
        <!-- <h3 style="color: #5233cc">升级数据</h3> -->
        <div class="hTitle">升级数据</div>
      </el-divider>
      <el-card class="box-card">
        <div class="upgrade">
          <div class="item">
            <h3 v-if="row.taskStatus == 'created'">未开始</h3>
            <h3 v-if="row.taskStatus == 'issued'">已开始</h3>
            <!-- <h3 v-if="row.taskStatus == 'issued'">升级中</h3> -->

            <span>任务状态</span>
          </div>
          <div class="item">
            <h3>{{ row.taskStartTime }}</h3>
            <span>任务时间</span>
          </div>
          <div class="item">
            <h3>{{ row.countCommand }}</h3>
            <span>计划升级数</span>
          </div>
          <div class="item">
            <h3>{{ row.countCommand }}</h3>
            <span>升级请求数</span>
          </div>
          <div class="item">
            <h3>{{ row.countCommandSuccess }}</h3>
            <span>升级成功数</span>
          </div>
          <div class="item">
            <h3>{{ row.countCommandFail }}</h3>
            <span>升级失败数</span>
          </div>
          <div class="item">
            <h3>{{ row.countCommandNoResponse }}</h3>
            <span>升级无响应数</span>
          </div>
          <div class="item">
            <h3>
              {{
                row.countCommand
                  ? (row.countCommandSuccess / row.countCommand) * 100 + "%"
                  : 0 + "%"
              }}
            </h3>
            <span>升级成功率</span>
          </div>
        </div>
      </el-card>
      <taskDeviceList :row="row" :taskRepeatNum="taskRepeatNum"/>
    </div>
  </div>
</template>

<script>
import taskDeviceList from "./taskDeviceList";
import * as taskApi from "@/api/link/task";

export default {
  //import引入的组件需要注入到对象中才能使用
  components: { taskDeviceList },
  data() {
    //这里存放数据
    return {
      row: this.$route.query,
      typeList: [
        // { value: 1, label: "获取设备信息" },
        // { value: 2, label: "系统文件下载" },
        // { value: 3, label: "系统文件下载状态查询" },
        { value: "DeviceState", label: "获取设备信息" },
        { value: "SoftwareLoad", label: "设备升级" },
        { value: "PatchLoad", label: "补丁升级" },
        { value: "SoftwareLoadStatus", label: "系统文件下载状态查询" },
        { value: "CfgfileLoad", label: "配置文件升级" },
        { value: "CfgfileLoadStatus", label: "配置文件升级状态查询" },
        { value: "SystemReboot", label: "重启设备" },
        { value: "LogfileUpload", label: "设备日志收集" },
        { value: "LogfileUploadNotify", label: "设备日志收集结果上报" },
        { value: "LogfileUploadStatus", label: "设备日志收集状态查询" },
        { value: "ShellScriptLoad", label: "应用升级" },
        { value: "ShellScriptLoadNotify", label: "可执行文件执行结果上报" },
        { value: "ShellScriptLoadStatus", label: "可执行文件执行状态查询" },
        { value: "EthStatus", label: "网络接口信息查询" },

      ],
      taskRepeatNum: ''
    };
  },
  beforeRouteLeave(to, from, next) {
    if (to.name == 'taskList') {
      next()
    } else {
      let f = localStorage.getItem('taskForms')
      if (f) {
        localStorage.removeItem('taskForms')
      }
      next()
    }
  },
  filters: {
    getTypeName(val, list) {
      var typeName = "";
      if (!val) {
        typeName = "";
      }
      list.map((item) => {
        if (val == item.value) {
          typeName = item.label;
        }
      });
      return typeName;
    },
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    // 将从分页接收的任务数据再通过findById接口调取详细数据
    // this.getData(this.row.id);
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() { },
  methods: {
    onBack() {
      this.$router.push({
        path: "/taskList",
      });
    },
    getData(id) {
      taskApi.getById(id).then((res) => {
        
        this.taskRepeatNum = res.data.taskRepeatNum
      });
    },
  },
};
</script>
<style lang='scss' scoped>
.comSpan {
  display: inline-block;
  width: 105px;
  text-align: right;
}
//@import url(); 引入公共css类
.taskOverview {
  position: relative;
  padding: 10px;
  .back {
    // position: fixed;
    // top: 60px;
    // right: 10px;
    // z-index: 99999;
  }
  .curTable {
    border-collapse: collapse;
    width: 100%;
    margin-top: 10px;
  }

  .curTable td {
    line-height: 2.5;
    font-size: 16px;
    // border-right: 1px solid;
  }
  .upgrade {
    display: flex;
    .item {
      flex: 1;
      width: 15%;
      text-align: center;
    }
  }
  .curTableOther {
    border-collapse: collapse;
    width: 100%;
    margin-top: 10px;
  }
  .curTableOther td {
    line-height: 2.5;
    text-align: center;
  }
}
</style>